<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    .box {
      width: 100px;
      height: 100px;
      background: palegreen;
      position: fixed;
    }
  </style>
</head>
<body>
  <div class="box"></div>
</body>
</html>
<script>
// 英文：
  // distance - 距离

// 需求：从左往右 移动 400px

// 动画的背景知识：
  // 动起来，帧速率；1S以内播放 图片(帧 - frame)的数量
  // 刷新率  ->  fps   ->  60HZ  ->  一般电脑 1S 刷新60次


const box = document.querySelector('.box');

box.addEventListener('click', e => {
  let distance = 0;

  const timeId = setInterval(() => {
    distance += 5;

    box.style.left = distance + 'px';

    if (distance > 400) {
      clearInterval(timeId);
    }
  }, 1000 / 60)
})
// console.log(box);
</script>